//
// Created by wopy on 2020/9/1.
//
#include <iostream>
#include "InputWord.hpp"

using namespace std;

INPUT_RETURN_VALUE doGetWordList(void *arg) {
    InputState *state = (InputState *) arg;
    FcitxInputState *input = state->getFcitxInputState();
    FcitxCandidateWordList *cand_list = state->getWordListAsZero();
    char *raw_buff = FcitxInputStateGetRawInputBuffer(input);
    if (FcitxInputStateGetRawInputBufferSize(input) < 50) {
        state->getCandidateWord(cand_list, raw_buff);
    }
    /* 显示输入的笔顺 */
    string msg = keyCode2Msg(raw_buff);  //将键码转换成为笔顺
    state->setMessage(msg);
    return IRV_DISPLAY_CANDWORDS;
}

string keyCode2Msg(const char *raw_buff) {
    //一丨丿丶ㄥ
    string res("");
    int len = strlen(raw_buff);
    for (int i = 0; i < len; ++i) {
        switch (raw_buff[i]) {
            case 'i':
                res += "一";
                break;
            case 'o':
                res += "丨";
                break;
            case 'p':
                res += "丿";
                break;
            case 'k':
                res += "丶";
                break;
            case 'l':
                res += "ㄥ";
                break;
            case 'm':
                res += "＊";
                break;
        }
    }
    return res;
}
